package net.chenlin.dp.modules.business.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.chenlin.dp.common.entity.Page;
import net.chenlin.dp.common.entity.R;
import net.chenlin.dp.modules.business.entity.dto.TcpLineChartQueryDto;
import net.chenlin.dp.modules.business.entity.vo.tcp.NewDataListVo;
import net.chenlin.dp.modules.business.entity.vo.tcp.TcpDataList;
import net.chenlin.dp.modules.business.service.TcpDataService;
import net.chenlin.dp.modules.sys.controller.AbstractController;
import net.chenlin.dp.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.Map;

/**
 * @author Yangsm
 * @ClassName: TcpDataController
 * @Description: TODO
 * @date 2023年03月09日 11:42
 */
@Slf4j
@RestController
@RequestMapping("/tcpData")
@Api(tags = "TCP数据展示")
public class TcpDataController extends AbstractController {

    @Autowired
    private TcpDataService tcpDataService;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(value = "展示TCP数据列表")
    public Page<TcpDataList> getTcpDataList(@RequestBody Map<String, Object> params) {
        return tcpDataService.getTcpDataList(params);
    }

    @RequestMapping(value = "/getTcpLineChart", method = RequestMethod.POST)
    @ApiOperation(value = "获取Tcp折线图数据")
    public R getTcpLineChart(@RequestBody TcpLineChartQueryDto queryDto) {
        R r = tcpDataService.getTcpLineChart(queryDto);
        return r;
    }

    @RequestMapping(value = "/getNewDatalist", method = RequestMethod.POST)
    @ApiOperation(value = "最新数据列表")
    public Page<NewDataListVo> getNewDatalist(@RequestBody Map<String, Object> params) {
        Serializable id = SecurityUtils.getSubject().getSession().getId();
        System.out.println(" ====== sessionId ======"+id);
        SysUserEntity user = getUser();
        if(null == user){
            log.info("未获取到当前登录用户！");
            return new Page<>();
        }
        if(user.getOrgId() != 1){
            params.put("orgId",user.getOrgId());
        }
        return tcpDataService.getNewDatalist(params);
    }

}
